package com.javasm.springmybatis.timer;

import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author：longjinyi
 * @Version：1.0
 * @Date：2021/12/30-8:49
 * @Since:jdk1.8
 * @Description:
 */
//2：JDK自带的Executors
//有线程池也可以做延时操作,但是无法指定具体时间执行,(无法实现某个月某一天执行)
public class ScheTimerTest {
    public static void main(String[] args) {
        //ScheduledThreadPoolExecutor的构造方法里面传自定义线程池中的线程数量当参数，即传corePoolSize
        ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(10);

        //创建循环，测试scheduledThreadPoolExecutor有无线程池
        for (int i = 0; i < 100; i++) {
            scheduledThreadPoolExecutor.schedule(
                    new Runnable() {
                        @Override
                        public void run() {
                            String name = Thread.currentThread().getName();
                            System.out.println("Executors========"+name);
                            System.out.println("4545454");
                        }

                        //2000:延迟时间
                        //TimeUnit.MILLISECONDS：设置延迟时间的单位是毫秒
                    }, 2000, TimeUnit.MILLISECONDS);
        }
    }
}
